import socket  
import struct
import rpcmsg_pb2
import time

pi_points = rpcmsg_pb2.PIPoints()
for i in range(0,200):
    pi_point = pi_points.pts.add()
    pi_point.pt = 35+i
    pi_point.val = 2.0+i
    pi_point.timestamp = (long)(time.time())



print pi_points

data_field = pi_points.SerializeToString()



client = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )

#set socket timeout
client.settimeout(2.0) 

svr_addr = ('localhost', 2161) 

longs = [0,105,0,0,0,0,0,0]
longs[7] = len(data_field)
print longs
msg_head = struct.pack('8i',*longs)

try:
    while 1:
        send_rs = client.sendto( msg_head+data_field, svr_addr ) 
        print 'send', send_rs, 'bytes'
        
        time.sleep(0.2)
    
    

        
except socket.error, msg:
    print msg
    
print 'end'